const express = require('express')

const {
	queryUser,
} = require('../modules/module-user')

const router = express.Router()

// /ult/login
router.post('/login', function(req, res, next) {
	queryUser(req.body).then(result => {
		result = Array.isArray(result) ? result[0] : result
		if (result && result.id)
			req.session.userInfo = result
		else
			result = {
				error: '用户名或密码错误！',
			}
		res.type('json').send(result)
	})
})

module.exports = router